<?php
namespace app\admin\controller\manager;

use app\admin\controller\Controller;
use app\admin\model\AdminMenu as AdminMenuModel;

class Menus extends Controller
{
    protected $model;
    /**
     * 构造方法
     * @access public
     * @param  App  $app  应用对象
     */
    public function initialize()
    {
        parent::initialize();
        // 控制器初始化
        $this->model = new AdminMenuModel;
    }
    // 获取全部菜单
    public function getMenuAll(){
       // 返回    
       return $this->renderSuccess($this->model->getMenuAll()['tree']);
    }

    // 添加菜单
    public function add()
    {
        if($this->model->add($this->request->only(['parent_id', 'name', 'url', 'ishidden', 'sort','icon','web_url'])))
        {
            return $this->renderSuccess([],'新增成功');
        }
        return $this->renderError($this->model->getError());
    }

    // 编辑菜单
    public function edit()
    {
        if($this->model->edit($this->request->only(['admin_menu_id','parent_id', 'name', 'url', 'ishidden', 'sort','icon','web_url'])))
        {
            return $this->renderSuccess([],'修改成功');
        }
        return $this->renderError($this->model->getError()??'修改失败');
    }

    // 删除菜单
    public function delete()
    {
        if($this->model->remove($this->request->param('admin_menu_id')))
        {
            return $this->renderSuccess([],'删除成功');
        }
        return $this->renderError($this->model->getError()??'删除失败');
    }

}